﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using UFIDA.U8.MomServiceCommon;
using UFIDA.U8.U8MOMAPIFramework;
using UFIDA.U8.U8APIFramework;
using UFIDA.U8.U8APIFramework.Meta;
using UFIDA.U8.U8APIFramework.Parameter;
using MSXML2;
using Trade.DBUtility.DataTableName;
using System.Collections;
using System.Reflection;
using System.IO;
using System.Xml;

namespace YYAPI
{
    public class coapi
    {
        #region 调用U8API的辅助类
        private void setAttribute(MSXML2.IXMLDOMElement nd, string name, object value)
        {
            string strValue = "";
            if (value != null && value != DBNull.Value)
                strValue = value.ToString();
            nd.setAttribute(name, strValue);
        }
        private bool SetModelValue(string FieldName, string Value, object obj)
        {
            try
            {
                Type Ts = obj.GetType();
                object v = Convert.ChangeType(Value, Ts.GetProperty(FieldName).PropertyType);
                Ts.GetProperty(FieldName).SetValue(obj, v, null);
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region CO成品入库单
        public string ToYYCCPRK(ADODB.Connection oCon, DataSet ds, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer, string strPKValue)
        {
            if (ds.Tables[0].DefaultView.Count == 0 || ds.Tables[1].DefaultView.Count == 0)
            {
                return "API接口传入的零件成品入库数据错误，数据行数为0!";
            }
            DataSet dsUser = new DataSet();
            try
            {
                dsUser = CustomizableDesignBLL.GetData("select * from UFSystem..UA_User where cUser_Id='" + sUserID + "'");
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
            //生产订单获取
            string MOID = "";
            for (int i = 0; i < ds.Tables[1].DefaultView.Count; i++)
            {
                if (MOID != "") MOID += ",";
                MOID += "'" + ds.Tables[1].DefaultView[i]["MOID"].ToString() + "'";
            }
            DataSet dsmom = new DataSet();
            string sql = "select a.*,b.MDeptCode,b.modid,b.sotype,b.socode,b.SoDId from " + strYongYouDBName + ".dbo.mom_order a inner join " + strYongYouDBName + ".dbo.mom_orderdetail b on a.moid=b.moid where a.MoId in(" + MOID + ")";
            try
            {
                dsmom = CustomizableDesignBLL.GetData(sql);
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

            // 返回值
            string strRet = "";
            string bz = ds.Tables[0].DefaultView[0]["BZ"].ToString();
            int index1 = bz.IndexOf('(');
            int index2 = bz.IndexOf(')');
            string bzcode = bz.Substring(index1 + 1, index2 - index1 - 1);
            //
            DateTime dtCreateDate = DateTime.Now;

            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            //string sSubId = "ST";
           string sSubId = "AS";
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            //
            //string strConn = "Data Source=" + Common.SQLServerName + ";User ID=" + Common.SQLServerUserName + ";Password=" + Common.SQLServerPassword + ";Initial Catalog=" + Common.YongYouDBName + ";Timeout=60";
            string strConn = u8Login.UFDataConnstringForNet;//"data source=10.101.163.122;user id=sa;password=1;initial catalog=UFDATA_002_2020;Connect Timeout=30;Persist Security Info=True";

            strConn = "Provider=SQLOLEDB;" + strConn;

            //ADODB.Connection oCon = new ADODB.Connection();
            //oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            //oCon.ConnectionString = strConn;
            //oCon.Open(strConn, "", "", -1);
            //
            IXMLDOMDocument2 domHead = new MSXML2.DOMDocument();
            IXMLDOMDocument2 domBody = new MSXML2.DOMDocument();
            MSXML2.IXMLDOMElement eleHead;
            MSXML2.IXMLDOMElement eleBody;
            MSXML2.IXMLDOMElement ele;
            ADODB.Recordset rs = new ADODB.Recordset();
            string strSQL;

            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;

            strSQL = "select * from dbo.RecordInQ where 1=0";//理论上要用视图名的,但是一直用表名,就用表名算了
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domHead, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();

            //增加表头数据节点z:row
            eleHead = domHead.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            ele = domHead.createElement("z:row");
            //'UPGRADE_WARNING: 未能解析对象 ele 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE
            eleHead.appendChild(ele);

            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domHead = broker.GetBoParam("domHead");
            //domHead.RowCount = 1; //设置BO对象(表头)行数，只能为一行
            //给BO对象(表头)的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            /****************************** 以下是必输字段 ****************************/
            setAttribute(ele, "id", "0"); //主关键字段，int类型
            setAttribute(ele, "ccode", "CPRK" + DateTime.Now.ToString("yyyyMMdd") + "0001"); //"0000000105"发货单号，string类型
            setAttribute(ele, "ddate", dtCreateDate.ToString("yyyy-MM-dd"));// dtCreateDate.ToString("yyyy-MM-dd");
            setAttribute(ele, "cwhcode", "0401"); //发货日期，DateTime类型
            setAttribute(ele, "iverifystate", "0");
            setAttribute(ele, "iswfcontrolled", "0");
            setAttribute(ele, "ireturncount", "0");
            setAttribute(ele, "cmemo", "PDA生成");
            //string usersql = "select * from ufsystem.[dbo].[UA_User] where cuser_id='" + sUserID + "'";
            //DataSet userDs = CustomizableDesignBLL.GetData(usersql);
            //if (userDs.Tables[0].DefaultView.Count == 0) { throw new Exception("未找到对应操作员!"); }
            //string username = userDs.Tables[0].DefaultView[0]["cuser_name"].ToString();
            setAttribute(ele, "cmaker", dsUser.Tables[0].DefaultView[0]["cUser_Name"].ToString());
            setAttribute(ele, "cbustype", "成品入库"); //发货日期，DateTime类型
            setAttribute(ele, "csource", "生产订单"); //发货日期，DateTime类型
            setAttribute(ele, "brdflag", "1");
            setAttribute(ele, "cvouchtype", "10");
            setAttribute(ele, "crdcode", "102");
            setAttribute(ele, "vt_id", "63");
            setAttribute(ele, "cdepcode", dsmom.Tables[0].DefaultView[0]["MDeptCode"].ToString()); //发货日期，DateTime类型
            setAttribute(ele, "cdefine10", ds.Tables[1].DefaultView[0]["SerialID"].ToString()); //发货日期，DateTime类型


            //给BO表体参数domBody赋值，此BO参数的业务类型为发货单，属表体参数。BO参数均按引用传递
            //提示：给BO表体参数domBody赋值有两种方法

            //方法一是直接传入MSXML2.DOMDocumentClass对象
            //broker.AssignNormalValue("domBody", new MSXML2.DOMDocumentClass())
            strSQL = "select * from dbo.RecordInSQ where 1=0";
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domBody, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();
            rs = null;

            //增加表体数据节点z:row
            eleBody = domBody.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domBody = broker.GetBoParam("domBody");
            //domBody.RowCount = 1; //设置BO对象行数
            //可以自由设置BO对象行数为大于零的整数，也可以不设置而自动增加行数
            //给BO对象的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            /****************************** 以下是必输字段 ****************************/
            for (int iRow = 0; iRow < ds.Tables[1].DefaultView.Count; iRow++)
            {
                ele = domBody.createElement("z:row");
                eleBody.appendChild(ele);
                //
                setAttribute(ele, "autoid", "0"); //这个值是什么意思？主关键字段，0类型
                setAttribute(ele, "cinvcode", ds.Tables[1].DefaultView[iRow]["cInvCode"].ToString()); //"01019002065"; //存货编码，string类型
                setAttribute(ele, "id", "0");
                setAttribute(ele, "editprop", "A"); //编辑属性：A表新增，M表修改，D表删除，string类型

                setAttribute(ele, "irowno", (iRow + 1).ToString()); //行号，string类型


                setAttribute(ele, "cdefine34", ds.Tables[1].DefaultView[iRow]["SerialID"].ToString());
                if (ds.Tables[1].DefaultView[iRow]["MoID"].ToString() != "")
                {
                    DataRow[] dr = dsmom.Tables[0].Select("MOID=" + ds.Tables[1].DefaultView[iRow]["MoID"].ToString());
                    if (dr.Length > 0)
                    {
                        setAttribute(ele, "cmocode", dr[0]["MoCode"].ToString());
                    }
                    //生产订单号，string类型
                }
                setAttribute(ele, "impoids", ds.Tables[1].DefaultView[iRow]["MoDId"].ToString());
                setAttribute(ele, "imoseq", ds.Tables[1].DefaultView[iRow]["MoRowNo"].ToString());
                setAttribute(ele, "cdefine25", ds.Tables[1].DefaultView[iRow]["SerialID"].ToString());

                decimal decSCQuantity = ds.Tables[1].DefaultView[iRow]["qty"] == DBNull.Value ? 0 : (decimal)ds.Tables[1].DefaultView[iRow]["qty"];
                decimal decLZQuantity = ds.Tables[1].DefaultView[iRow]["qty"] == DBNull.Value ? 0 : (decimal)ds.Tables[1].DefaultView[iRow]["qty"];
                setAttribute(ele, "iquantity", Trade.DBUtility.Common.decimalEx.RoundEx(decLZQuantity, 2));
                setAttribute(ele, "cbatch", ds.Tables[1].DefaultView[iRow]["cBatch"].ToString());


                //setAttribute(ele, "cinva_unit", ds.Tables["T_rdrecords10_scandetails"].DefaultView[iRow]["cAssUnit"]);
                //setAttribute(ele, "cassunit", "0402"); //"01019002065"; //存货编码，string类型
                //setAttribute(ele, "cinvdefine3", ds.Tables["T_rdrecords10_scandetails"].DefaultView[iRow]["cinvdefine3"]);
                //setAttribute(ele, "cinvdefine4", ds.Tables["T_rdrecords10_scandetails"].DefaultView[iRow]["cinvdefine4"]);
                //  setAttribute(ele, "cposition", ds.Tables["T_rdrecords10_scandetails"].DefaultView[iRow]["cPosition"]);
                //setAttribute(ele, "inum", ds.Tables["T_rdrecords10_scandetails"].DefaultView[iRow]["inum"]);
                //string barcode = ds.Tables["T_rdrecords10_scandetails"].DefaultView[iRow]["barcode"].ToString();
                //string defSql = "select * from t_barcode where barcode='" + barcode + "'";
                //DataSet defDs = CustomizableDesignBLL.GetData(defSql);

                //setAttribute(ele, "cdefine26", defDs.Tables[0].DefaultView[0]["JZ"]); //"01019002065"; //存货编码，string类型
                //setAttribute(ele, "cdefine27", defDs.Tables[0].DefaultView[0]["LuNo"]); //"01019002065"; //存货编码，string类型
                //setAttribute(ele, "cdefine31", barcode);
                //setAttribute(ele, "cdefine34", defDs.Tables[0].DefaultView[0]["cdefine34"].ToString()); //"01019002065"; //存货编码，string类型

                //setAttribute(ele, "cdefine31", ds.Tables["T_rdrecords10_scandetails"].DefaultView[iRow]["barcode"]);
                setAttribute(ele, "bcosting", "1");
                setAttribute(ele, "isotype", "0");
                setAttribute(ele, "bvmiused", "0");
                setAttribute(ele, "iordertype", "0");
                setAttribute(ele, "iexpiratdatecalcu", "0");
                setAttribute(ele, "cmworkcentercode", "0015");
                setAttribute(ele, "iinvsncount", Convert.ToInt64(decLZQuantity));
                //增加需求分类关联号
                if (ds.Tables[1].DefaultView[iRow]["MoID"].ToString() != "")
                {
                    DataRow[] dr = dsmom.Tables[0].Select("MODID=" + ds.Tables[1].DefaultView[iRow]["MoDId"].ToString());
                    if (dr.Length > 0)
                    {
                        setAttribute(ele, "isotype", dr[0]["sotype"].ToString());
                        setAttribute(ele, "csocode", dr[0]["socode"].ToString());
                        setAttribute(ele, "isodid", dr[0]["SoDId"].ToString());
                    }
                    //生产订单号，string类型
                }

            }

            string errMsg = "";
            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }
            object domPosition = null;
            //ADODB.Connection cnnFrom = null;
            string VouchId = "";
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            bool bCheck = true;
            bool bBeforCheckStock = true;
            bool bIsRedVouch = false;
            string sAddedState = "";
            bool bReMote = false;
            string voucherType = "10";
            errMsg = "";
            //bool Insert(string sVouchType, object DomHead, object domBody, object domPosition, ref string errMsg, ref Connection cnnFrom = null, ref string VouchId = null, ref IXMLDOMDocument2 domMsg = null, ref bool bCheck = true, ref bool bBeforCheckStock = true, bool bIsRedVouch = false, string sAddedState = "", bool bReMote = false);
            object[] args = new object[] { voucherType, domHead, domBody, domPosition, errMsg, oCon, VouchId, domMsg, bCheck, bBeforCheckStock, bIsRedVouch, sAddedState, bReMote };
            string[] paras = { "sVouchType", "DomHead", "domBody", "domPosition", "errMsg", "cnnFrom", "VouchId", "domMsg", "bCheck", "bBeforCheckStock", "bIsRedVouch", "sAddedState", "bReMote" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            //pMod[5] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Insert", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                //oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[4].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }

            return "";
        }

        //成品入库单审核
        public string ToYYCCPRK_Audit(ADODB.Connection oCon, string id, string utfs1, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            string strResult = string.Empty;
            DateTime dtCreateDate = DateTime.Now;
            ////
            //string strYongYouDBName = "UFDATA_997_2016";
            //string sAccID = strZT;
            //string sYear = dtCreateDate.ToString("yyyy");
            //string sUserID = "sb01";
            //string sPassword = "";
            //string sDate = dtCreateDate.ToString("yyyy-MM-dd");
            //string sServer = "127.0.0.1";// strServerIP;
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
          string sSubId = "AS";
            //string sAccID = Custom.UI.Common.YongYouAccID;
            //string sYear = Custom.UI.Common.YongYouYear;
            //string sUserID = Custom.UI.Common.YongYouUserID;
            //string sPassword = Custom.UI.Common.YongYouPassword;
            //string sDate = Custom.UI.Common.YongYouDate;
            //string sServer = "127.0.0.1";// Custom.UI.Common.YongYouServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                return "登录失败，原因：" + u8Login.ShareString;
            }
            string errMsg = "";

            //string strConn = u8Login.UFDataConnstringForNet;
            //strConn = "Provider=SQLOLEDB;" + strConn;
            ////string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            //ADODB.Connection oCon = new ADODB.Connection();
            //oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            //oCon.ConnectionString = strConn;
            //oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            string VouchId = id;
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "10";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = utfs1;
            object[] args = new object[] { voucherType, VouchId, errMsg,oCon, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "cnnFrom", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Verify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {

                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                
                //oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                //if (errMsg == null)
                //    errMsg = "错误：但是没有出错信息";
                //return "失败:" + errMsg;
            }

            return "";
        }


        #endregion

        #region CO销售出库单
        public string ToYYXSCK(ADODB.Connection oCon, DataSet ds, DataSet dsToU8, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer, string strPKValue)
        {
            if (ds.Tables[0].DefaultView.Count == 0)
            {
                return "成品出库单据不能为空";
            }
            DataSet dsUser = new DataSet();
            try
            {
                dsUser = CustomizableDesignBLL.GetData("select * from UFSystem..UA_User where cUser_Id='" + sUserID + "'");
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
          string sSubId = "AS";

            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            //
            //string strConn = "Data Source=" + Common.SQLServerName + ";User ID=" + Common.SQLServerUserName + ";Password=" + Common.SQLServerPassword + ";Initial Catalog=" + Common.YongYouDBName + ";Timeout=60";
            string strConn = u8Login.UFDataConnstringForNet;//"data source=10.101.163.122;user id=sa;password=1;initial catalog=UFDATA_002_2020;Connect Timeout=30;Persist Security Info=True";

            //strConn = "Provider=SQLOLEDB;" + strConn;

            //ADODB.Connection oCon = new ADODB.Connection();
            //oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            //oCon.ConnectionString = strConn;
            //oCon.Open(strConn, "", "", -1);
            //
            MSXML2.IXMLDOMDocument2 domHead = new MSXML2.DOMDocument();
            MSXML2.IXMLDOMDocument2 domBody = new MSXML2.DOMDocument();
            MSXML2.IXMLDOMElement eleHead;
            MSXML2.IXMLDOMElement eleBody;
            MSXML2.IXMLDOMElement ele;
            ADODB.Recordset rs = new ADODB.Recordset();
            string strSQL;

            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;

            strSQL = "select * from dbo.KCSaleOutH where 1=0";//理论上要用视图名的,但是一直用表名,就用表名算了
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domHead, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();

            //增加表头数据节点z:row
            eleHead = domHead.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            ele = domHead.createElement("z:row");
            //'UPGRADE_WARNING: 未能解析对象 ele 的默认属性。 单击以获得更多信息:“
            eleHead.appendChild(ele);

            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domHead = broker.GetBoParam("domHead");
            //domHead.RowCount = 1; //设置BO对象(表头)行数，只能为一行
            //给BO对象(表头)的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            /****************************** 以下是必输字段 ****************************/
            setAttribute(ele, "id", "0"); //主关键字段，int类型
            setAttribute(ele, "ccode", "XSCK" + DateTime.Now.ToString("yyyyMMdd") + "0001"); //"0000000105"发货单号，string类型
            setAttribute(ele, "ddate", DateTime.Now.ToString("yyyy-MM-dd")); 
            setAttribute(ele, "cbustype", dsToU8.Tables[0].DefaultView[0]["cbustype"].ToString());
            setAttribute(ele, "iverifystate", "0");
            setAttribute(ele, "iswfcontrolled", "0");

            setAttribute(ele, "cmaker", dsUser.Tables[0].DefaultView[0]["cUser_Name"].ToString());
            setAttribute(ele, "cvouchtype", "32");
            setAttribute(ele, "csource", "发货单");
            setAttribute(ele, "cwhcode", ds.Tables[0].DefaultView[0]["cWhCode"].ToString());
            setAttribute(ele, "brdflag", "0");
            setAttribute(ele, "crdcode", "201");
            setAttribute(ele, "ccuscode", dsToU8.Tables[0].DefaultView[0]["ccuscode"].ToString());
            setAttribute(ele, "ireturncount", "0");
            setAttribute(ele, "cmemo", "PDA生成");
            setAttribute(ele, "bisstqc", "0");
            setAttribute(ele, "vt_id", "87");


            setAttribute(ele, "ireturncount", "0");//客户自定义项1，string类型
            setAttribute(ele, "cbuscode", dsToU8.Tables[0].DefaultView[0]["cDLCode"].ToString()); //客户自定义项2，string类型
            setAttribute(ele, "cmemo", "PDA生成"); //客户自定义项4，string类型

            string cdepcode = dsToU8.Tables[0].DefaultView[0]["cdepcode"].ToString();
            setAttribute(ele, "cdepcode", cdepcode);
            setAttribute(ele, "cstcode", dsToU8.Tables[0].DefaultView[0]["cstcode"].ToString());
            setAttribute(ele, "cdlcode", dsToU8.Tables[0].DefaultView[0]["DLID"].ToString());

            setAttribute(ele, "cpersoncode", dsToU8.Tables[0].DefaultView[0]["cpersoncode"].ToString()); //客户自定义项3，string类型
            setAttribute(ele, "cdefine1", dsToU8.Tables[0].DefaultView[0]["cdefine1"].ToString());
            setAttribute(ele, "cdefine2", dsToU8.Tables[0].DefaultView[0]["cdefine2"].ToString());
            setAttribute(ele, "cdefine3", dsToU8.Tables[0].DefaultView[0]["cdefine3"].ToString());
            setAttribute(ele, "cdefine4", dsToU8.Tables[0].DefaultView[0]["cdefine4"].ToString());
            setAttribute(ele, "cdefine5", dsToU8.Tables[0].DefaultView[0]["cdefine5"].ToString());
            setAttribute(ele, "cdefine6", dsToU8.Tables[0].DefaultView[0]["cdefine6"].ToString());
            setAttribute(ele, "cdefine7", dsToU8.Tables[0].DefaultView[0]["cdefine7"].ToString());
            setAttribute(ele, "cdefine8", dsToU8.Tables[0].DefaultView[0]["cdefine8"].ToString());
            setAttribute(ele, "cdefine9", dsToU8.Tables[0].DefaultView[0]["cdefine9"].ToString());
            setAttribute(ele, "cdefine11", dsToU8.Tables[0].DefaultView[0]["cdefine11"].ToString());
            setAttribute(ele, "cdefine12", dsToU8.Tables[0].DefaultView[0]["cdefine12"].ToString());
            setAttribute(ele, "cdefine13", dsToU8.Tables[0].DefaultView[0]["cdefine13"].ToString());
            setAttribute(ele, "cdefine14", dsToU8.Tables[0].DefaultView[0]["cdefine14"].ToString());
            setAttribute(ele, "cdefine15", dsToU8.Tables[0].DefaultView[0]["cdefine15"].ToString());
            setAttribute(ele, "cdefine16", dsToU8.Tables[0].DefaultView[0]["cdefine16"].ToString());
            setAttribute(ele, "cdefine10", strPKValue);
            //给BO表体参数domBody赋值，此BO参数的业务类型为发货单，属表体参数。BO参数均按引用传递
            //提示：给BO表体参数domBody赋值有两种方法

            //方法一是直接传入MSXML2.DOMDocumentClass对象
            //broker.AssignNormalValue("domBody", new MSXML2.DOMDocumentClass())
            strSQL = "select * from dbo.KCSaleOutB where 1=0";
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domBody, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();
            rs = null;

            //增加表体数据节点z:row
            eleBody = domBody.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domBody = broker.GetBoParam("domBody");
            //domBody.RowCount = 1; //设置BO对象行数
            //可以自由设置BO对象行数为大于零的整数，也可以不设置而自动增加行数
            //给BO对象的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            /****************************** 以下是必输字段 ****************************/
            int ij = 0;
            ds.Tables[1].Columns.Add("ddty", typeof(string));
            for (int i = 0; i < ds.Tables[1].DefaultView.Count; i++)
            {
                ds.Tables[1].DefaultView[i]["ddty"] = "0";
            }
            for (int iRow = 0; iRow < dsToU8.Tables[1].DefaultView.Count; iRow++)
            {
                decimal fqty= decimal.Parse(dsToU8.Tables[1].DefaultView[iRow]["fOutQuantity"] == DBNull.Value ? "0" : dsToU8.Tables[1].DefaultView[iRow]["fOutQuantity"].ToString());
                decimal taskqty = decimal.Parse(dsToU8.Tables[1].DefaultView[iRow]["iQuantity"].ToString()) - fqty;
                string strInvCode = dsToU8.Tables[1].DefaultView[iRow]["cinvcode"].ToString();
                string strbatch = dsToU8.Tables[1].DefaultView[iRow]["cDefine33"].ToString();

                int c = 0;
                for (int i = 0; i < ds.Tables[1].DefaultView.Count; i++)
                {
                    if (strInvCode == ds.Tables[1].DefaultView[i]["cInvCode"].ToString() && ds.Tables[1].DefaultView[i]["ddty"].ToString() == "0" && taskqty > 0 && strbatch == ds.Tables[1].DefaultView[i]["cBatch"].ToString())
                    {
                        c++;
                        ds.Tables[1].DefaultView[i]["ddty"] = "1";
                        ds.Tables[1].DefaultView[i].EndEdit();
                        if (c == taskqty)
                        {
                            break;
                        }
                    }

                }
                if (c == 0 || taskqty == 0) continue;
                ele = domBody.createElement("z:row"); 
                
                //
                setAttribute(ele, "autoid", "0"); //这个值是什么意思？主关键字段，0类型
                setAttribute(ele, "iquantity", c); //数量，double类型
                setAttribute(ele, "cinvcode", strInvCode); //"01019002065"; //存货编码，string类型
                setAttribute(ele, "id", "0");
                setAttribute(ele, "editprop", "A"); //编辑属性：A表新增，M表修改，D表删除，string类型

                setAttribute(ele, "irowno", (iRow + 1).ToString()); //行号，string类型

                if (dsToU8.Tables[1].DefaultView[iRow]["cdemandcode"] != DBNull.Value)
                {

                    setAttribute(ele, "isodid", dsToU8.Tables[1].DefaultView[iRow]["cdemandcode"].ToString());
                    setAttribute(ele, "isotype", dsToU8.Tables[1].DefaultView[iRow]["idemandtype"].ToString());
                    setAttribute(ele, "csocode", dsToU8.Tables[1].DefaultView[iRow]["cdemandcode"].ToString());


                }

                setAttribute(ele, "bvmiused", "0"); //"01019002065"; //存货编码，string类型
                setAttribute(ele, "cbdlcode", dsToU8.Tables[0].DefaultView[0]["cDLCode"].ToString()); //"01019002065"; //存货编码，string类型
                setAttribute(ele, "bcosting", "1"); //"01019002065"; //存货编码，string类型

                setAttribute(ele, "cdefine22", dsToU8.Tables[1].DefaultView[iRow]["cdefine22"]);
                setAttribute(ele, "cdefine23", dsToU8.Tables[1].DefaultView[iRow]["cdefine23"]);
                setAttribute(ele, "cdefine24", dsToU8.Tables[1].DefaultView[iRow]["cdefine24"]);
                setAttribute(ele, "cdefine25", dsToU8.Tables[1].DefaultView[iRow]["cdefine25"]);
                setAttribute(ele, "cdefine26", dsToU8.Tables[1].DefaultView[iRow]["cdefine26"]);
                setAttribute(ele, "cdefine28", dsToU8.Tables[1].DefaultView[iRow]["cdefine28"]);
                setAttribute(ele, "cdefine29", dsToU8.Tables[1].DefaultView[iRow]["cdefine29"]);
                setAttribute(ele, "cdefine30", dsToU8.Tables[1].DefaultView[iRow]["cdefine30"]);
                setAttribute(ele, "cdefine31", dsToU8.Tables[1].DefaultView[iRow]["cdefine31"]);
                setAttribute(ele, "cdefine32", dsToU8.Tables[1].DefaultView[iRow]["cdefine32"]);
                setAttribute(ele, "cdefine33", dsToU8.Tables[1].DefaultView[iRow]["cdefine33"]);
                setAttribute(ele, "cdefine34", dsToU8.Tables[1].DefaultView[iRow]["cdefine34"]);
                setAttribute(ele, "cdefine35", dsToU8.Tables[1].DefaultView[iRow]["cdefine35"]);
                setAttribute(ele, "cdefine36", dsToU8.Tables[1].DefaultView[iRow]["cdefine36"]);
                setAttribute(ele, "cdefine37", dsToU8.Tables[1].DefaultView[iRow]["cdefine37"]); 

                setAttribute(ele, "cdefine27", strPKValue); //"01019002065"; //存货编码，string类型

                setAttribute(ele, "idlsid", dsToU8.Tables[1].DefaultView[iRow]["idlsid"].ToString());
                setAttribute(ele, "cbatch", strbatch); //"01019002065"; //存货编码，string类型
                eleBody.appendChild(ele);
            }

            //string errMsg = "";
            //Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            //object objPCO = System.Activator.CreateInstance(oType);
            //object[] par = new object[] { u8Login, errMsg };
            //bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            //if (!bSuccess)
            //{
            //    if (errMsg == null)
            //        errMsg = "错误：但是没有出错信息";
            //    return errMsg;
            //}
            //object domPosition = null;
            ////ADODB.Connection cnnFrom = null;
            //string VouchId = "";
            //MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            //bool bCheck = true;
            //bool bBeforCheckStock = true;
            //bool bIsRedVouch = false;
            //string sAddedState = "";
            //bool bReMote = false;
            //string voucherType = "32";
            //string id = "";
            //errMsg = "";
            ////bool Insert(string sVouchType, object DomHead, object domBody, object domPosition, ref string errMsg, ref Connection cnnFrom = null, ref string VouchId = null, ref IXMLDOMDocument2 domMsg = null, ref bool bCheck = true, ref bool bBeforCheckStock = true, bool bIsRedVouch = false, string sAddedState = "", bool bReMote = false);
            //object[] args = new object[] { voucherType, domHead, domBody, domPosition, errMsg, VouchId,null, domMsg, bCheck, bBeforCheckStock, bIsRedVouch, sAddedState, bReMote };
            //string[] paras = { "sVouchType", "DomHead", "domBody", "domPosition", "errMsg", "VouchId", "cnnFrom", "domMsg", "bCheck", "bBeforCheckStock", "bIsRedVouch", "sAddedState", "bReMote" };
            //ParameterModifier pMod = new ParameterModifier(13);
            //pMod[4] = true;
            //pMod[5] = true;
            //pMod[6] = true;
            //pMod[7] = true;
            //pMod[8] = true;
            //pMod[9] = true;
            //ParameterModifier[] mods = { pMod };
            ////oCon.BeginTrans();
            //bool res = (bool)oType.InvokeMember("Insert", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);

            Yonyou.U8.CoApi.Server.ApiSTBase st = new Yonyou.U8.CoApi.Server.ApiSTBase(u8Login, "32");
            string errMsg = "";
            IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            bool bcheck = true;
            bool bBeforeCheck = true;
            bool bIsRed =  false;
            string sRet = "";
            string VoucherCode = "";

            //UFIDA.U8.PUB.LogHelper.WriteLine("head:" + domHead.xml);
            //UFIDA.U8.PUB.LogHelper.WriteLine("body:" + domBody.xml);

            st.Init(ref errMsg, "", "", 0, false);
            bool res = st.VoucherAdd(domHead, domBody, ref errMsg, ref domMsg, ref bcheck, ref bBeforeCheck, ref bIsRed, ref VoucherCode, ref sRet);

            if (!string.IsNullOrEmpty(errMsg))
            {
                UFIDA.U8.PUB.LogHelper.WriteLine("ERROR:" + errMsg);
                //WriteLog.WriteLine("KCSaleOutHelper", "Add", errMsg);
                throw new Exception(errMsg);
            }
            

            if (res)
            {
                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
               // oCon.RollbackTrans();
                u8Login.ShutDown();
                //errMsg = args[4].ToString();
                //String js = domMsg.xml;

                //object domMsgRet = args[4];
                //throw new Exception("保存报错" + domMsg.ToString());
                //domMsg = (MSXML2.IXMLDOMDocument2)domMsgRet;

                IXMLDOMDocument2 xmldoc = new MSXML2.DOMDocument();
                //throw new Exception(domMsg.xml.ToString());
                xmldoc.loadXML(domMsg.xml.ToString());

                StringReader str = null;
                XmlTextReader reader = null;
                DataSet xmlDs = new DataSet();
                str = new StringReader(xmldoc.xml);

                reader = new XmlTextReader(str);
                xmlDs.ReadXml(reader);
                reader.Close();
                if (string.IsNullOrEmpty(errMsg))
                {
                    if (xmlDs.Tables[0].DefaultView.Count > 0)
                    {
                        DataTable dt = xmlDs.Tables["row"];
                        for (int i = 0; i < dt.DefaultView.Count; i++)
                        {
                            string cinvcode = dt.DefaultView[i]["cinvcode"].ToString();
                            string cfree2 = dt.DefaultView[i]["cfree2"].ToString();
                            string iqty = dt.DefaultView[i]["iquantity"].ToString();
                            string inum = dt.DefaultView[i]["inum"].ToString();
                            string iaqty = dt.DefaultView[i]["iavaquantity"].ToString();
                            string ianum = dt.DefaultView[i]["iavanum"].ToString();
                            errMsg = errMsg + "存货:" + cinvcode + " " + cfree2 + "库存不足," + "消耗数量:" + iqty + "件数:" + inum + ",库存数量:" + iaqty + "件数:" + ianum + "\r\n";
                        }
                    }
                    if (errMsg == null)
                        errMsg = "错误：但是没有出错信息";

                }
                return "失败:" + errMsg;
            }


            //return "";
        }
        //销售出库单审核
        public string ToYYXSCK_Audit(ADODB.Connection oCon, string strID, string strutfs1, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer)
        {
            
            string strResult = string.Empty;
            DateTime dtCreateDate = DateTime.Now;
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
          string sSubId = "AS";

            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";

            //string strConn = u8Login.UFDataConnstringForNet;
            //strConn = "Provider=SQLOLEDB;" + strConn;
            ////string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            //ADODB.Connection oCon = new ADODB.Connection();
            //oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            //oCon.ConnectionString = strConn;
            //oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            ////API参数赋值s
            string VouchId = strID;
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "32";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = strutfs1;
            object[] args = new object[] { voucherType, VouchId, errMsg, oCon, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "cnnFrom", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Verify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            //Yonyou.U8.CoApi.Server.ApiSTBase st = new Yonyou.U8.CoApi.Server.ApiSTBase(u8Login, "32");
            //string errMsg = "";
            //IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            //bool bcheck = true;
            //bool bBeforeCheck = true; 
             

            //st.Init(ref errMsg);
            //bool res = st.VoucherVerify(strID, ref errMsg, ref domMsg, ref bcheck, ref bBeforeCheck);

            if (res)
            {
                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
               // oCon.RollbackTrans();
                u8Login.ShutDown();

                errMsg = args[2].ToString();
                String js = domMsg.xml;

                object domMsgRet = args[5];

                domMsg = (MSXML2.IXMLDOMDocument2)domMsgRet;
                UFIDA.U8.PUB.LogHelper.WriteLine("AUDIT ERROR:" + errMsg);
                UFIDA.U8.PUB.LogHelper.WriteLine("AUDIT ERROR:" + js);
                //MSXML2.IXMLDOMDocument2 xmldoc = new MSXML2.DOMDocument();
                //xmldoc.loadXML(domMsg.xml.ToString());
                //if (string.IsNullOrEmpty(xmldoc.xml.ToString())) {
                //    errMsg = "审核错误：" + errMsg;
                //    return errMsg;
                //}
                //StringReader str = null;
                //XmlTextReader reader = null;
                //DataSet xmlDs = new DataSet();
                //str = new StringReader(xmldoc.xml);

                //reader = new XmlTextReader(str);
              
                //xmlDs.ReadXml(reader);
                ////throw new Exception("审核报错2" + xmldoc.xml.ToString());
                //reader.Close();
                //if (string.IsNullOrEmpty(errMsg))
                //{
                //    DataTable dt = xmlDs.Tables["row"];
                //    for (int i = 0; i < dt.DefaultView.Count; i++)
                //    {
                //        string cinvcode = dt.DefaultView[i]["cinvcode"].ToString();
                //        string cfree2 = dt.DefaultView[i]["cfree2"].ToString();
                //        string iqty = dt.DefaultView[i]["iquantity"].ToString();
                //        string inum = dt.DefaultView[i]["inum"].ToString();
                //        string iaqty = dt.DefaultView[i]["iavaquantity"].ToString();
                //        string ianum = dt.DefaultView[i]["iavanum"].ToString();
                //        errMsg = errMsg + "存货:" + cinvcode + " " + cfree2 + "库存不足," + "消耗数量:" + iqty + "件数:" + inum + ",库存数量:" + iaqty + "件数:" + ianum + "\r\n";
                //    }
                //    if (errMsg == null)
                //        errMsg = "审核错误：但是没有出错信息";

                //}
            }
            return errMsg;
        }

        //销售出库单弃审
        public string ToYYXSCK_UnAudit(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
           string sSubId = "AS";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "32";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Unverify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
               // oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }
        //销售出库单删除
        public string ToYYXSCK_Delete(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
           string sSubId = "AS";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "32";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Delete", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                //oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }

        #endregion


        #region CO采购入库单
        public string ToYYCGRK(ADODB.Connection oCon, DataSet ds, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer, string strPKValue, string tm)
        {
            if (ds.Tables[0].DefaultView.Count == 0 || ds.Tables[1].DefaultView.Count == 0)
            {
                return "API接口传入的零件成品入库数据错误，数据行数为0!";
            }
            DataSet dsUser = new DataSet();
            try
            {
                dsUser = CustomizableDesignBLL.GetData("select * from UFSystem..UA_User where cUser_Id='" + sUserID + "'");
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

            // 返回值
            string strRet = "";
            //string bz = ds.Tables[0].DefaultView[0]["BZ"].ToString();
            //int index1 = bz.IndexOf('(');
            //int index2 = bz.IndexOf(')');
            //string bzcode = bz.Substring(index1 + 1, index2 - index1 - 1);
            //
            DateTime dtCreateDate = DateTime.Now;

            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
          string sSubId = "AS";
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            //
            //string strConn = "Data Source=" + Common.SQLServerName + ";User ID=" + Common.SQLServerUserName + ";Password=" + Common.SQLServerPassword + ";Initial Catalog=" + Common.YongYouDBName + ";Timeout=60";
            string strConn = u8Login.UFDataConnstringForNet;//"data source=10.101.163.122;user id=sa;password=1;initial catalog=UFDATA_002_2020;Connect Timeout=30;Persist Security Info=True";

            //strConn = "Provider=SQLOLEDB;" + strConn;

            //ADODB.Connection oCon = new ADODB.Connection();
            //oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            //oCon.ConnectionString = strConn;
            //oCon.Open(strConn, "", "", -1);
            //
            IXMLDOMDocument2 domHead = new MSXML2.DOMDocument();
            IXMLDOMDocument2 domBody = new MSXML2.DOMDocument();
            MSXML2.IXMLDOMElement eleHead;
            MSXML2.IXMLDOMElement eleBody;
            MSXML2.IXMLDOMElement ele;
            ADODB.Recordset rs = new ADODB.Recordset();
            string strSQL;

            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;

            strSQL = "select * from dbo.zpurRkdHead where 1=0";//理论上要用视图名的,但是一直用表名,就用表名算了
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domHead, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();

            //增加表头数据节点z:row
            eleHead = domHead.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            ele = domHead.createElement("z:row");
            //'UPGRADE_WARNING: 未能解析对象 ele 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE
            eleHead.appendChild(ele);

            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domHead = broker.GetBoParam("domHead");
            //domHead.RowCount = 1; //设置BO对象(表头)行数，只能为一行
            //给BO对象(表头)的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义
            int ccode = 1000000001;
            /****************************** 以下是必输字段 ****************************/
            setAttribute(ele, "id", "0"); //主关键字段，int类型
            setAttribute(ele, "ccode", ccode); //"0000000105"发货单号，string类型
            setAttribute(ele, "ddate", dtCreateDate.ToString("yyyy-MM-dd")); //dtCreateDate.ToString("yyyy-MM-dd");
            setAttribute(ele, "cwhcode", "0401");
            setAttribute(ele, "btransflag", "0");
            setAttribute(ele, "iverifystate", "0");
            setAttribute(ele, "iswfcontrolled", "0");
            setAttribute(ele, "ireturncount", "0");
            setAttribute(ele, "cmemo", "PDA生成");
            setAttribute(ele, "cmaker", dsUser.Tables[0].DefaultView[0]["cUser_Name"].ToString());
            setAttribute(ele, "cbustype", "普通采购");
            setAttribute(ele, "csource", "采购订单");
            setAttribute(ele, "brdflag", "1");
            setAttribute(ele, "cvouchtype", "01");
            setAttribute(ele, "crdcode", "101");
            setAttribute(ele, "editprop", "A");
            setAttribute(ele, "vt_id", "27");

            setAttribute(ele, "cdefine10", tm);
            setAttribute(ele, "iexchrate", "1");
            setAttribute(ele, "cexch_name", "人民币");
            setAttribute(ele, "cptcode", "01");
            setAttribute(ele, "cvencode", ds.Tables["po_pomain"].DefaultView[0]["cvencode"].ToString());
            string itaxrate = ds.Tables["po_pomain"].DefaultView[0]["itaxrate"].ToString();
            decimal itax = decimal.Parse(itaxrate);
            setAttribute(ele, "itaxrate", itax.ToString("#0.000000"));
            setAttribute(ele, "cordercode", ds.Tables["po_pomain"].DefaultView[0]["cpoid"].ToString());
            setAttribute(ele, "ipurorderid", ds.Tables["po_pomain"].DefaultView[0]["poid"].ToString());


            //给BO表体参数domBody赋值，此BO参数的业务类型为发货单，属表体参数。BO参数均按引用传递
            //提示：给BO表体参数domBody赋值有两种方法

            //方法一是直接传入MSXML2.DOMDocumentClass对象
            //broker.AssignNormalValue("domBody", new MSXML2.DOMDocumentClass())
            strSQL = "select * from dbo.zpurRkdTail where 1=0";
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domBody, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();
            rs = null;

            //增加表体数据节点z:row
            eleBody = domBody.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domBody = broker.GetBoParam("domBody");
            //domBody.RowCount = 1; //设置BO对象行数
            //可以自由设置BO对象行数为大于零的整数，也可以不设置而自动增加行数
            //给BO对象的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            /****************************** 以下是必输字段 ****************************/
            for (int iRow = 0; iRow < ds.Tables["v_cginstorage"].DefaultView.Count; iRow++)
            {
                ele = domBody.createElement("z:row");
                eleBody.appendChild(ele);
                //
                setAttribute(ele, "autoid", "0"); //这个值是什么意思？主关键字段，0类型

                setAttribute(ele, "cinvcode", ds.Tables["v_cginstorage"].DefaultView[iRow]["cinvcode"].ToString());
                setAttribute(ele, "id", "0");
                setAttribute(ele, "editprop", "A"); //编辑属性：A表新增，M表修改，D表删除，string类型

                setAttribute(ele, "irowno", (iRow + 1).ToString()); //行号，string类型

                setAttribute(ele, "cdefine33", ds.Tables["v_cginstorage"].DefaultView[iRow]["Define33"].ToString());
                setAttribute(ele, "cdefine34", ds.Tables["v_cginstorage"].DefaultView[iRow]["id"].ToString());

                setAttribute(ele, "iposid", ds.Tables["v_cginstorage"].DefaultView[iRow]["id"].ToString());
                setAttribute(ele, "cdefine25", tm);
                decimal decLZQuantity = decimal.Parse(ds.Tables["v_cginstorage"].DefaultView[iRow]["iQuantity"].ToString());
                setAttribute(ele, "inquantity", Trade.DBUtility.Common.decimalEx.RoundEx(decLZQuantity, 2));
                setAttribute(ele, "iquantity", Trade.DBUtility.Common.decimalEx.RoundEx(decLZQuantity, 2));
                setAttribute(ele, "cbatch", ds.Tables["v_cginstorage"].DefaultView[iRow]["Define33"].ToString());//
              
                setAttribute(ele, "bcosting", "1");
                setAttribute(ele, "bvmiused", "0");
                setAttribute(ele, "iordertype", "0");
                setAttribute(ele, "iexpiratdatecalcu", "0");
                setAttribute(ele, "iinvsncount", Convert.ToInt64(decLZQuantity));
             
                decimal price = decimal.Parse(ds.Tables["v_cginstorage"].DefaultView[iRow]["iTaxPrice"].ToString());
                decimal wsprice = price / (itax / 100 + 1);
                decimal sum = Math.Round(price * decLZQuantity, 2);
                decimal wssum = Math.Round(wsprice * decLZQuantity, 2);
                //
                setAttribute(ele, "iunitcost", wsprice.ToString("#0.000000"));
                setAttribute(ele, "ioritaxcost", price.ToString("#0.000000"));
                setAttribute(ele, "ioricost", wsprice.ToString("#0.000000"));
                setAttribute(ele, "iorimoney", wssum.ToString("#0.00"));
                setAttribute(ele, "ioritaxprice", (sum - wssum).ToString("#0.00"));
                setAttribute(ele, "iorisum", sum.ToString("#0.00"));
                setAttribute(ele, "itaxrate", itax.ToString("#0.000000"));
                setAttribute(ele, "itaxprice", (sum - wssum).ToString("#0.00"));
                setAttribute(ele, "isum", sum.ToString("#0.00"));
                setAttribute(ele, "iprice", wssum.ToString("#0.00"));

                //增加需求分类关联号
                if (ds.Tables["v_cginstorage"].DefaultView[iRow]["id"].ToString() != "")
                {
                    DataRow[] dr = ds.Tables["po_podetails"].Select("id=" + ds.Tables["v_cginstorage"].DefaultView[iRow]["id"].ToString());
                    if (dr.Length > 0)
                    {
                        setAttribute(ele, "isotype", dr[0]["sotype"].ToString());

                        setAttribute(ele, "csocode", dr[0]["csocode"].ToString());

                        setAttribute(ele, "isodid", dr[0]["sodid"].ToString());

                        setAttribute(ele, "cpoid", dr[0]["cpoid"].ToString());
                        setAttribute(ele, "chvencode", dr[0]["cvencode"].ToString());
                    }
                    //生产订单号，string类型
                }
               


            }

            string errMsg = "";
            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }
            object domPosition = null;
            //ADODB.Connection cnnFrom = null;
            string VouchId = "";
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            bool bCheck = true;
            bool bBeforCheckStock = true;
            bool bIsRedVouch = false;
            string sAddedState = "";
            bool bReMote = false;
            string voucherType = "01";
            errMsg = "";
            //bool Insert(string sVouchType, object DomHead, object domBody, object domPosition, ref string errMsg, ref Connection cnnFrom = null, ref string VouchId = null, ref IXMLDOMDocument2 domMsg = null, ref bool bCheck = true, ref bool bBeforCheckStock = true, bool bIsRedVouch = false, string sAddedState = "", bool bReMote = false);
            object[] args = new object[] { voucherType, domHead, domBody, domPosition, errMsg, oCon, VouchId, domMsg, bCheck, bBeforCheckStock, bIsRedVouch, sAddedState, bReMote };
            string[] paras = { "sVouchType", "DomHead", "domBody", "domPosition", "errMsg", "cnnFrom", "VouchId", "domMsg", "bCheck", "bBeforCheckStock", "bIsRedVouch", "sAddedState", "bReMote" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            //pMod[5] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Insert", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                //oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[4].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }

            return "";
        }

        //采购入库单审核
        public string ToYYCGRK_Audit(ADODB.Connection oCon, string id, string utfs1, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer)
        {
            string strResult = string.Empty;
            DateTime dtCreateDate = DateTime.Now;
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
          string sSubId = "AS";

            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";

            //string strConn = u8Login.UFDataConnstringForNet;
            //strConn = "Provider=SQLOLEDB;" + strConn;
            ////string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon1 = new ADODB.Connection();
            //oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            //oCon.ConnectionString = strConn;
            //oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            string VouchId = id;
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "01";
          
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = utfs1;
            object[] args = new object[] { voucherType, VouchId, errMsg, oCon1, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg","cnnFrom", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Verify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {

                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {

                //oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (string.IsNullOrEmpty(errMsg)) {
                    return "";
                }
                return "失败:" + errMsg;
            }

            return "";
        }

        //成品入库单弃审
        public string ToYYCGRK_UnAudit(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
           string sSubId = "AS";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "01";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Unverify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                //oCon.RollbackTrans();
                u8Login.ShutDown();

                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }
        //成品入库单删除
        public string ToYYCGRK_Delete(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
           string sSubId = "AS";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "01";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Delete", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                //oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                //string errMsg1 = args[2].ToString();
                //object domMsgRet = args[4];
                //domMsg = (MSXML2.IXMLDOMDocument2)domMsgRet;

                //MSXML2.IXMLDOMDocument2 xmldoc = new MSXML2.DOMDocument();
                //xmldoc.loadXML(domMsg.xml.ToString());

                //StringReader str = null;
                //XmlTextReader reader = null;
                //DataSet xmlDs = new DataSet();
                //str = new StringReader(xmldoc.xml);

                //reader = new XmlTextReader(str);
                //xmlDs.ReadXml(reader);
                //reader.Close();

                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }

        #endregion

        #region 调拨单
        public string ToYYDBD(ADODB.Connection oCon, DataSet ds, DataSet dsToU8, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer, string strPKValue)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            //
            //string strConn = "Data Source=" + Common.SQLServerName + ";User ID=" + Common.SQLServerUserName + ";Password=" + Common.SQLServerPassword + ";Initial Catalog=" + Common.YongYouDBName + ";Timeout=60";
            string strConn = u8Login.UFDataConnstringForNet;//"data source=10.101.163.122;user id=sa;password=1;initial catalog=UFDATA_002_2020;Connect Timeout=30;Persist Security Info=True";

            //strConn = "Provider=SQLOLEDB;" + strConn;
            //
            IXMLDOMDocument2 domHead = new MSXML2.DOMDocument();
            IXMLDOMDocument2 domBody = new MSXML2.DOMDocument();
            MSXML2.IXMLDOMElement eleHead;
            MSXML2.IXMLDOMElement eleBody;
            MSXML2.IXMLDOMElement ele;
            ADODB.Recordset rs = new ADODB.Recordset();
            string strSQL;

            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;

            strSQL = "select * from TransM where 1=0";//理论上要用视图名的,但是一直用表名,就用表名算了
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domHead, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();

            //增加表头数据节点z:row
            eleHead = domHead.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            ele = domHead.createElement("z:row");
            //'UPGRADE_WARNING: 未能解析对象 ele 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE
            eleHead.appendChild(ele);

            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domHead = broker.GetBoParam("domHead");
            //domHead.RowCount = 1; //设置BO对象(表头)行数，只能为一行
            //给BO对象(表头)的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            setAttribute(ele, "id", "0"); //主关键字段，int类型
            setAttribute(ele, "ctvcode", "11"); //单据号，string类型
            setAttribute(ele, "dtvdate", DateTime.Now.ToString()); //日期，DateTime类型
            setAttribute(ele, "ireturncount", "0"); //ireturncount，string类型
            setAttribute(ele, "iverifystate", "0"); //iverifystate，string类型
            setAttribute(ele, "iswfcontrolled", "0"); //iswfcontrolled，string类型
            setAttribute(ele, "cbustype", ""); //业务类型，string类型
            setAttribute(ele, "ctvmemo", "PDA生成");
            setAttribute(ele, "csource", "1");
            string usersql = "select * from ufsystem.[dbo].[UA_User] where cuser_id='" + sUserID + "'";
            DataSet userDs = CustomizableDesignBLL.GetData(usersql);
            if (userDs.Tables[0].DefaultView.Count == 0) { throw new Exception("未找到对应操作员!"); }
            string username = userDs.Tables[0].DefaultView[0]["cuser_name"].ToString();
            setAttribute(ele, "cmaker", username);
            //setAttribute(ele, "cmaker", dsData.Tables["T_TransVouch_scandetails"].DefaultView[0]["cmaker"].ToString());
            setAttribute(ele, "codepcode", dsToU8.Tables["ST_AppTransVouch"].DefaultView[0]["cODepCode"].ToString());
            setAttribute(ele, "cidepcode", dsToU8.Tables["ST_AppTransVouch"].DefaultView[0]["cIDepCode"].ToString());
            setAttribute(ele, "cordcode", dsToU8.Tables["ST_AppTransVouch"].DefaultView[0]["cORdCode"].ToString());
            setAttribute(ele, "cirdcode", dsToU8.Tables["ST_AppTransVouch"].DefaultView[0]["cIRdCode"].ToString());
            setAttribute(ele, "ciwhcode", dsToU8.Tables["ST_AppTransVouch"].DefaultView[0]["cIWhCode"].ToString());
            setAttribute(ele, "cowhcode", dsToU8.Tables["ST_AppTransVouch"].DefaultView[0]["cOWhCode"].ToString());
            setAttribute(ele, "vt_id", "89");
            setAttribute(ele, "itransflag", "正向");
            setAttribute(ele, "cdefine10", strPKValue);
            setAttribute(ele, "ctranrequestcode", dsToU8.Tables["ST_AppTransVouch"].DefaultView[0]["ctvcode"].ToString());

            //broker.AssignNormalValue("domHead", domHead);

            //给BO表体参数domBody赋值，此BO参数的业务类型为销售订单，属表体参数。BO参数均按引用传递
            //提示：给BO表体参数domBody赋值有两种方法

            //方法一是直接传入MSXML2.DOMDocumentClass对象
            //broker.AssignNormalValue("domBody", new MSXML2.DOMDocumentClass())
            strSQL = "select * from TransD  where 1=0";
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domBody, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();
            rs = null;

            //增加表体数据节点z:row
            eleBody = domBody.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domBody = broker.GetBoParam("domBody");
            //domBody.RowCount = 1; //设置BO对象行数
            //可以自由设置BO对象行数为大于零的整数，也可以不设置而自动增加行数
            //给BO对象的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义


            /****************************** 以下是必输字段 ****************************/
            for (int iRow = 0; iRow < ds.Tables["t_dbhz"].DefaultView.Count; iRow++)
            {

                ele = domBody.createElement("z:row");
                eleBody.appendChild(ele);

                setAttribute(ele, "autoid", "0"); //主关键字段，int类型
                setAttribute(ele, "cinvcode",ds.Tables["t_dbhz"].DefaultView[iRow]["cInvCode"].ToString()); //存货编码，string类型
                setAttribute(ele, "editprop", "A"); //编辑属性：A表新增，M表修改，D表删除，string类型
                setAttribute(ele, "irowno", (iRow + 1).ToString());
                string cinvcode =ds.Tables["t_dbhz"].DefaultView[0]["cInvCode"].ToString();
                DataSet cinvcodeDs = CustomizableDesignBLL.GetData("select cComUnitCode from " + strYongYouDBName + ".DBO.inventory where cinvcode='" + cinvcode + "'");
                setAttribute(ele, "cinvm_unit", cinvcodeDs.Tables[0].DefaultView[0][0].ToString());// "01"; //仓库编码，string类型
                //domBodyWraper.SetAttribute("igrouptype", "2");
                decimal Quantity = decimal.Parse(ds.Tables["t_dbhz"].DefaultView[iRow]["qty"].ToString());
                setAttribute(ele, "itvquantity", Quantity);
                //setAttribute(ele, "itvnum", "1");
                setAttribute(ele, "ctvbatch",ds.Tables["t_dbhz"].DefaultView[iRow]["cBatch"]);
                //cinposcode coutposcode
                setAttribute(ele, "iexpiratdatecalcu", "0");
                setAttribute(ele, "itrids", ds.Tables["t_dbhz"].DefaultView[iRow]["dbid"]);
                setAttribute(ele, "iinvsncount", Quantity);//
                setAttribute(ele, "cdefine27", strPKValue);

                setAttribute(ele, "issotype", "4");
                setAttribute(ele, "issodid", ds.Tables["t_dbhz"].DefaultView[iRow]["cBatch"]);
                setAttribute(ele, "idsotype", "4");
                setAttribute(ele, "idsodid", ds.Tables["t_dbhz"].DefaultView[iRow]["cBatch"]);
            }

            string errMsg = "";
            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }
            object domPosition = null;
            //ADODB.Connection cnnFrom = null;
            string VouchId = "";
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            bool bCheck = true;
            bool bBeforCheckStock = true;
            bool bIsRedVouch = false;
            string sAddedState = "";
            bool bReMote = false;
            string voucherType = "12";
            errMsg = "";
            //bool Insert(string sVouchType, object DomHead, object domBody, object domPosition, ref string errMsg, ref Connection cnnFrom = null, ref string VouchId = null, ref IXMLDOMDocument2 domMsg = null, ref bool bCheck = true, ref bool bBeforCheckStock = true, bool bIsRedVouch = false, string sAddedState = "", bool bReMote = false);
            object[] args = new object[] { voucherType, domHead, domBody, domPosition, errMsg, null, VouchId, domMsg, bCheck, bBeforCheckStock, bIsRedVouch, sAddedState, bReMote };
            string[] paras = { "sVouchType", "DomHead", "domBody", "domPosition", "errMsg", "cnnFrom", "VouchId", "domMsg", "bCheck", "bBeforCheckStock", "bIsRedVouch", "sAddedState", "bReMote" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            //pMod[5] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Insert", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                //oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                //oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[4].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                if (errMsg.Length > 50) { errMsg = errMsg.Substring(0, 40); }
                return "失败:" + errMsg;
            }
        }
        //其他出库单审核
        public string ToYYDBD_Audit(ADODB.Connection oCon, string strID, string strutfs1, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";

            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            //ADODB.Connection oCon = new ADODB.Connection();
            //oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            //oCon.ConnectionString = strConn;
            //oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "12";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object[] args = new object[] { voucherType, strID, errMsg, strutfs1, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            //oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Verify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
               // oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                //oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
            return "";
        }

        //其他出库单弃审
        public string ToYYDBD_UnAudit(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "12";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Unverify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }
        //其他出库单删除
        public string ToYYDBD_Delete(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "12";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Delete", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }

        #endregion

        #region CO其他出库单
        public string ToYYQTCK(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            DateTime dtNow = Convert.ToDateTime(strDate);

            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            //
            //string strConn = "Data Source=" + Common.SQLServerName + ";User ID=" + Common.SQLServerUserName + ";Password=" + Common.SQLServerPassword + ";Initial Catalog=" + Common.YongYouDBName + ";Timeout=60";
            string strConn = u8Login.UFDataConnstringForNet;//"data source=10.101.163.122;user id=sa;password=1;initial catalog=UFDATA_002_2020;Connect Timeout=30;Persist Security Info=True";

            strConn = "Provider=SQLOLEDB;" + strConn;

            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);
            //
            IXMLDOMDocument2 domHead = new MSXML2.DOMDocument();
            IXMLDOMDocument2 domBody = new MSXML2.DOMDocument();
            MSXML2.IXMLDOMElement eleHead;
            MSXML2.IXMLDOMElement eleBody;
            MSXML2.IXMLDOMElement ele;
            ADODB.Recordset rs = new ADODB.Recordset();
            string strSQL;

            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;

            strSQL = "select * from dbo.KCOtherOutH where 1=0";//理论上要用视图名的,但是一直用表名,就用表名算了
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domHead, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();

            //增加表头数据节点z:row
            eleHead = domHead.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            ele = domHead.createElement("z:row");
            //'UPGRADE_WARNING: 未能解析对象 ele 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE
            eleHead.appendChild(ele);

            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domHead = broker.GetBoParam("domHead");
            //domHead.RowCount = 1; //设置BO对象(表头)行数，只能为一行
            //给BO对象(表头)的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            /****************************** 以下是必输字段 ****************************/
            setAttribute(ele, "id", "0"); //主关键字段，int类型
            setAttribute(ele, "ccode", "11"); //"0000000105"发货单号，string类型
            setAttribute(ele, "ddate", DateTime.Now.ToString("yyyy-MM-dd")); //发货日期，DateTime类型
            setAttribute(ele, "cbustype", "其他出库");
            setAttribute(ele, "iverifystate", "0");
            setAttribute(ele, "iswfcontrolled", "0");
            string usersql = "select * from ufsystem.[dbo].[UA_User] where cuser_id='" + sUserID + "'";
            DataSet userDs = CustomizableDesignBLL.GetData(usersql);
            if (userDs.Tables[0].DefaultView.Count == 0) { throw new Exception("未找到对应操作员!"); }
            string username = userDs.Tables[0].DefaultView[0]["cuser_name"].ToString();
            setAttribute(ele, "cmaker", username);
            setAttribute(ele, "cvouchtype", "09");
            setAttribute(ele, "cwhcode", dsData.Tables["T_PDStorageProduct"].DefaultView[0]["cwhcode"]);
            setAttribute(ele, "brdflag", "0");
            //setAttribute(ele, "ccuscode", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cCusCode"].ToString());
            setAttribute(ele, "ireturncount", "0");
            setAttribute(ele, "cmemo", "盘点生成");
            setAttribute(ele, "cdepcode", dsData.Tables["T_PDStorageProduct"].DefaultView[0]["cDepCode"]);
            setAttribute(ele, "crdcode", "210");// dsData.Tables["T_PDStorageProduct"].DefaultView[0]["cordcode"].ToString());
            setAttribute(ele, "vt_id", "85");


            //setAttribute(ele, "cdefine1", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine1"].ToString());//客户自定义项1，string类型
            //setAttribute(ele, "cdefine2", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine2"].ToString()); //客户自定义项2，string类型
            //setAttribute(ele, "cdefine3", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine3"].ToString()); //客户自定义项3，string类型
            //setAttribute(ele, "cdefine8", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine8"].ToString()); //客户自定义项4，string类型
            //setAttribute(ele, "cdefine9", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine9"].ToString()); //客户自定义项5，string类型
            setAttribute(ele, "cdefine10", dsData.Tables["T_PDStorage"].DefaultView[0]["SerialNum"]); //客户自定义项6，string类型


            //给BO表体参数domBody赋值，此BO参数的业务类型为发货单，属表体参数。BO参数均按引用传递
            //提示：给BO表体参数domBody赋值有两种方法

            //方法一是直接传入MSXML2.DOMDocumentClass对象
            //broker.AssignNormalValue("domBody", new MSXML2.DOMDocumentClass())
            strSQL = "select * from dbo.KCOtherOutB where 1=0";
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domBody, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();
            rs = null;

            //增加表体数据节点z:row
            eleBody = domBody.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domBody = broker.GetBoParam("domBody");
            //domBody.RowCount = 1; //设置BO对象行数
            //可以自由设置BO对象行数为大于零的整数，也可以不设置而自动增加行数
            //给BO对象的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            /****************************** 以下是必输字段 ****************************/
            for (int iRow = 0; iRow < dsData.Tables["T_PK"].DefaultView.Count; iRow++)
            {
                ele = domBody.createElement("z:row");
                eleBody.appendChild(ele);
                //
                setAttribute(ele, "autoid", "0"); //这个值是什么意思？主关键字段，0类型
                setAttribute(ele, "cinvcode", dsData.Tables["T_PK"].DefaultView[iRow]["cInvCode"].ToString()); //"01019002065"; //存货编码，string类型
                setAttribute(ele, "id", "0");
                setAttribute(ele, "editprop", "A"); //编辑属性：A表新增，M表修改，D表删除，string类型

                setAttribute(ele, "irowno", (iRow + 1).ToString()); //行号，string类型
                //setAttribute(ele,"snlist"] = ""; //序列号，string类型
                setAttribute(ele, "iquantity", dsData.Tables["T_PK"].DefaultView[iRow]["qty"].ToString()); //数量，double类型
                setAttribute(ele, "inquantity", dsData.Tables["T_PK"].DefaultView[iRow]["qty"].ToString()); //数量，double类型
                setAttribute(ele, "inum", dsData.Tables["T_PK"].DefaultView[iRow]["num"].ToString()); //数量，double类型
                setAttribute(ele, "innum", dsData.Tables["T_PK"].DefaultView[iRow]["num"].ToString()); //数量，double类型


                //setAttribute(ele, "cunitid", dsData.Tables["T_RdRecords09_scandetails"].DefaultView[iRow]["cComUnit"].ToString());// "01"; //仓库编码，string类型
                //string cinvcode = dsData.Tables["T_RdRecords09_scandetails"].DefaultView[iRow]["cInvCode"].ToString();
                //DataSet cinvcodeDs = CustomizableDesignBLL.GetData("select cComUnitCode from " + strYongYouDBName + ".DBO.inventory where cinvcode='" + cinvcode + "'");
                //setAttribute(ele, "cassunit", cinvcodeDs.Tables[0].DefaultView[0][0].ToString());// "01"; //仓库编码，string类型
                //domBodyWraper.SetAttribute("cgroupcode", "04");
                //domBodyWraper.SetAttribute("igrouptype", "2");
                //setAttribute(ele, "cgroupcode", "01");// 
                setAttribute(ele, "cinvm_unit", dsData.Tables["T_PK"].DefaultView[iRow]["MainUnit"]);
                setAttribute(ele, "cinva_unit", dsData.Tables["T_PK"].DefaultView[iRow]["SendUnit"]);
                setAttribute(ele, "cbatch", dsData.Tables["T_PK"].DefaultView[iRow]["cCVBatch"]);// "01"; //仓库编码，string类型
                setAttribute(ele, "cfree1", dsData.Tables["T_PK"].DefaultView[iRow]["vfree1"]);// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree2", dsData.Tables["T_PK"].DefaultView[iRow]["cfree2"] );// "01"; //仓库编码，string类型
                setAttribute(ele, "cfree3", dsData.Tables["T_PK"].DefaultView[iRow]["vfree3"]);// "01"; //仓库编码，string类型
                setAttribute(ele, "cposition", dsData.Tables["T_PK"].DefaultView[iRow]["cPosition"]);

                setAttribute(ele, "cinvdefine1", dsData.Tables["T_PK"].DefaultView[iRow]["cInvDefine1"]);
                setAttribute(ele, "cinvdefine3", dsData.Tables["T_PK"].DefaultView[iRow]["cInvDefine3"]);
                setAttribute(ele, "cinvdefine4", dsData.Tables["T_PK"].DefaultView[iRow]["cInvDefine4"]);
                setAttribute(ele, "cbatchproperty7", dsData.Tables["T_PK"].DefaultView[iRow]["cBatchPty7"]);
                //setAttribute(ele, "cfree4", dsData.Tables["T_PK"].DefaultView[iRow]["cfree4"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree5", dsData.Tables["T_PK"].DefaultView[iRow]["cfree5"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree6", dsData.Tables["T_PK"].DefaultView[iRow]["cfree6"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree7", dsData.Tables["T_PK"].DefaultView[iRow]["cfree7"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree8", dsData.Tables["T_PK"].DefaultView[iRow]["cfree8"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree9", dsData.Tables["T_PK"].DefaultView[iRow]["cfree9"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree10", dsData.Tables["T_PK"].DefaultView[iRow]["cfree10"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine22", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine22"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine23", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine23"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine24", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine24"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine25", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine25"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine26", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine26"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine27", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine27"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine28", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine28"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine29", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine29"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine30", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine30"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine31", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine31"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine32", dsData.Tables["T_PK"].DefaultView[iRow]["cdefine32"] );// "01"; //仓库编码，string类型


            }

            string errMsg = "";
            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }
            object domPosition = null;
            ADODB.Connection cnnFrom = null;
            string VouchId = "";
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            bool bCheck = true;
            bool bBeforCheckStock = true;
            bool bIsRedVouch = false;
            string sAddedState = "";
            bool bReMote = false;
            string voucherType = "09";
            errMsg = "";
            //bool Insert(string sVouchType, object DomHead, object domBody, object domPosition, ref string errMsg, ref Connection cnnFrom = null, ref string VouchId = null, ref IXMLDOMDocument2 domMsg = null, ref bool bCheck = true, ref bool bBeforCheckStock = true, bool bIsRedVouch = false, string sAddedState = "", bool bReMote = false);
            object[] args = new object[] { voucherType, domHead, domBody, domPosition, errMsg, VouchId, domMsg, bCheck, bBeforCheckStock, bIsRedVouch, sAddedState, bReMote };
            string[] paras = { "sVouchType", "DomHead", "domBody", "domPosition", "errMsg", "VouchId", "domMsg", "bCheck", "bBeforCheckStock", "bIsRedVouch", "sAddedState", "bReMote" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            //pMod[5] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Insert", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[4].ToString();
                domMsg = (IXMLDOMDocument2)args[6];
                String js = domMsg.xml;
                if (string.IsNullOrEmpty(errMsg))
                    errMsg = js;
                return "失败:" + errMsg;
            }

            return "";
        }
        //其他出库单审核
        public string ToYYQTCK_Audit(ADODB.Connection oCon, string id, string utfs1, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            //string sAccID = strAccID;
            //string sYear = strYear;
            //string sUserID = strUserID;
            //string sPassword = strPassword;
            //string sDate = strDate;
            //string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";

            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            //ADODB.Connection oCon = new ADODB.Connection();
            //oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            //oCon.ConnectionString = strConn;
            //oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            string VouchId = id;
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "09";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = utfs1;
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Verify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
            return "";
        }

        //其他出库单弃审
        public string ToYYQTCK_UnAudit(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "09";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Unverify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }
        //其他出库单删除
        public string ToYYQTCK_Delete(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "09";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Delete", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }

        #endregion

        #region CO其他入库单
        public string ToYYQTRK(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            DateTime dtNow = Convert.ToDateTime(strDate);

            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            //
            //string strConn = "Data Source=" + Common.SQLServerName + ";User ID=" + Common.SQLServerUserName + ";Password=" + Common.SQLServerPassword + ";Initial Catalog=" + Common.YongYouDBName + ";Timeout=60";
            string strConn = u8Login.UFDataConnstringForNet;//"data source=10.101.163.122;user id=sa;password=1;initial catalog=UFDATA_002_2020;Connect Timeout=30;Persist Security Info=True";

            strConn = "Provider=SQLOLEDB;" + strConn;

            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);
            //
            IXMLDOMDocument2 domHead = new MSXML2.DOMDocument();
            IXMLDOMDocument2 domBody = new MSXML2.DOMDocument();
            MSXML2.IXMLDOMElement eleHead;
            MSXML2.IXMLDOMElement eleBody;
            MSXML2.IXMLDOMElement ele;
            ADODB.Recordset rs = new ADODB.Recordset();
            string strSQL;

            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;

            strSQL = "select * from dbo.KCOtherInH where 1=0";//理论上要用视图名的,但是一直用表名,就用表名算了
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domHead, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();

            //增加表头数据节点z:row
            eleHead = domHead.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            ele = domHead.createElement("z:row");
            //'UPGRADE_WARNING: 未能解析对象 ele 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE
            eleHead.appendChild(ele);

            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domHead = broker.GetBoParam("domHead");
            //domHead.RowCount = 1; //设置BO对象(表头)行数，只能为一行
            //给BO对象(表头)的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            /****************************** 以下是必输字段 ****************************/
            setAttribute(ele, "id", "0"); //主关键字段，int类型
            setAttribute(ele, "ccode", "11"); //"0000000105"发货单号，string类型
            setAttribute(ele, "ddate", DateTime.Now.ToString("yyyy-MM-dd")); //发货日期，DateTime类型
            setAttribute(ele, "cbustype", "其他入库");
            setAttribute(ele, "iverifystate", "0");
            setAttribute(ele, "iswfcontrolled", "0");
            string usersql = "select * from ufsystem.[dbo].[UA_User] where cuser_id='" + sUserID + "'";
            DataSet userDs = CustomizableDesignBLL.GetData(usersql);
            if (userDs.Tables[0].DefaultView.Count == 0) { throw new Exception("未找到对应操作员!"); }
            string username = userDs.Tables[0].DefaultView[0]["cuser_name"].ToString();
            setAttribute(ele, "cmaker", username);
            setAttribute(ele, "cvouchtype", "08");
            setAttribute(ele, "cwhcode", dsData.Tables["T_PDStorageProduct"].DefaultView[0]["cwhcode"]);
            setAttribute(ele, "brdflag", "0");
            //setAttribute(ele, "ccuscode", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cCusCode"].ToString());
            setAttribute(ele, "ireturncount", "0");
            setAttribute(ele, "cmemo", "盘点生成");
            setAttribute(ele, "cdepcode", dsData.Tables["T_PDStorageProduct"].DefaultView[0]["cDepCode"]);
            setAttribute(ele, "crdcode", "108");// dsData.Tables["T_PDStorageProduct"].DefaultView[0]["cordcode"].ToString());
            setAttribute(ele, "vt_id", "67");


            //setAttribute(ele, "cdefine1", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine1"].ToString());//客户自定义项1，string类型
            //setAttribute(ele, "cdefine2", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine2"].ToString()); //客户自定义项2，string类型
            //setAttribute(ele, "cdefine3", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine3"].ToString()); //客户自定义项3，string类型
            //setAttribute(ele, "cdefine8", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine8"].ToString()); //客户自定义项4，string类型
            //setAttribute(ele, "cdefine9", dsData.Tables["T_RdRecord09_scandetails"].DefaultView[0]["cdefine9"].ToString()); //客户自定义项5，string类型
            setAttribute(ele, "cdefine10", dsData.Tables["T_PDStorage"].DefaultView[0]["SerialNum"]); //客户自定义项6，string类型


            //给BO表体参数domBody赋值，此BO参数的业务类型为发货单，属表体参数。BO参数均按引用传递
            //提示：给BO表体参数domBody赋值有两种方法

            //方法一是直接传入MSXML2.DOMDocumentClass对象
            //broker.AssignNormalValue("domBody", new MSXML2.DOMDocumentClass())
            strSQL = "select * from dbo.KCOtherInB where 1=0";
            rs.Open(strSQL, oCon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
            rs.Save(domBody, ADODB.PersistFormatEnum.adPersistXML);
            rs.Close();
            rs = null;

            //增加表体数据节点z:row
            eleBody = domBody.selectSingleNode("//rs:data") as MSXML2.IXMLDOMElement;
            //方法二是构造BusinessObject对象，具体方法如下：
            //BusinessObject domBody = broker.GetBoParam("domBody");
            //domBody.RowCount = 1; //设置BO对象行数
            //可以自由设置BO对象行数为大于零的整数，也可以不设置而自动增加行数
            //给BO对象的字段赋值，值可以是真实类型，也可以是无类型字符串
            //以下代码示例只设置第一行值。各字段定义详见API服务接口定义

            /****************************** 以下是必输字段 ****************************/
            for (int iRow = 0; iRow < dsData.Tables["T_PY"].DefaultView.Count; iRow++)
            {
                ele = domBody.createElement("z:row");
                eleBody.appendChild(ele);
                //
                setAttribute(ele, "autoid", "0"); //这个值是什么意思？主关键字段，0类型
                setAttribute(ele, "cinvcode", dsData.Tables["T_PY"].DefaultView[iRow]["cInvCode"].ToString()); //"01019002065"; //存货编码，string类型
                setAttribute(ele, "id", "0");
                setAttribute(ele, "editprop", "A"); //编辑属性：A表新增，M表修改，D表删除，string类型

                setAttribute(ele, "irowno", (iRow + 1).ToString()); //行号，string类型
                //setAttribute(ele,"snlist"] = ""; //序列号，string类型
                setAttribute(ele, "iquantity", dsData.Tables["T_PY"].DefaultView[iRow]["qty"].ToString()); //数量，double类型
                setAttribute(ele, "inquantity", dsData.Tables["T_PY"].DefaultView[iRow]["qty"].ToString()); //数量，double类型
                setAttribute(ele, "inum", dsData.Tables["T_PY"].DefaultView[iRow]["num"].ToString()); //数量，double类型
                setAttribute(ele, "innum", dsData.Tables["T_PY"].DefaultView[iRow]["num"].ToString()); //数量，double类型


                //setAttribute(ele, "cunitid", dsData.Tables["T_RdRecords09_scandetails"].DefaultView[iRow]["cComUnit"].ToString());// "01"; //仓库编码，string类型
                //string cinvcode = dsData.Tables["T_RdRecords09_scandetails"].DefaultView[iRow]["cInvCode"].ToString();
                //DataSet cinvcodeDs = CustomizableDesignBLL.GetData("select cComUnitCode from " + strYongYouDBName + ".DBO.inventory where cinvcode='" + cinvcode + "'");
                setAttribute(ele, "cassunit", "0402");// "01"; //仓库编码，string类型
                //domBodyWraper.SetAttribute("cgroupcode", "04");
                //domBodyWraper.SetAttribute("igrouptype", "2");
                //setAttribute(ele, "cgroupcode", "01");// 
                setAttribute(ele, "cinvm_unit", dsData.Tables["T_PY"].DefaultView[iRow]["MainUnit"]);
                setAttribute(ele, "cinva_unit", dsData.Tables["T_PY"].DefaultView[iRow]["SendUnit"]);
                setAttribute(ele, "cbatch", dsData.Tables["T_PY"].DefaultView[iRow]["cCVBatch"]);// "01"; //仓库编码，string类型
                setAttribute(ele, "cfree1", dsData.Tables["T_PY"].DefaultView[iRow]["vfree1"]);// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree2", dsData.Tables["T_PY"].DefaultView[iRow]["cfree2"] );// "01"; //仓库编码，string类型
                setAttribute(ele, "cfree3", dsData.Tables["T_PY"].DefaultView[iRow]["vfree3"]);// "01"; //仓库编码，string类型
                setAttribute(ele, "cposition", dsData.Tables["T_PY"].DefaultView[iRow]["cPosition"]);

                setAttribute(ele, "cinvdefine1", dsData.Tables["T_PY"].DefaultView[iRow]["cInvDefine1"]);
                setAttribute(ele, "cinvdefine3", dsData.Tables["T_PY"].DefaultView[iRow]["cInvDefine3"]);
                setAttribute(ele, "cinvdefine4", dsData.Tables["T_PY"].DefaultView[iRow]["cInvDefine4"]);
                setAttribute(ele, "cbatchproperty7", dsData.Tables["T_PY"].DefaultView[iRow]["cBatchPty7"]);
                //setAttribute(ele, "cfree4", dsData.Tables["T_PY"].DefaultView[iRow]["cfree4"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree5", dsData.Tables["T_PY"].DefaultView[iRow]["cfree5"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree6", dsData.Tables["T_PY"].DefaultView[iRow]["cfree6"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree7", dsData.Tables["T_PY"].DefaultView[iRow]["cfree7"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree8", dsData.Tables["T_PY"].DefaultView[iRow]["cfree8"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree9", dsData.Tables["T_PY"].DefaultView[iRow]["cfree9"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cfree10", dsData.Tables["T_PY"].DefaultView[iRow]["cfree10"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine22", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine22"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine23", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine23"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine24", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine24"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine25", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine25"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine26", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine26"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine27", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine27"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine28", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine28"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine29", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine29"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine30", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine30"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine31", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine31"] );// "01"; //仓库编码，string类型
                //setAttribute(ele, "cdefine32", dsData.Tables["T_PY"].DefaultView[iRow]["cdefine32"] );// "01"; //仓库编码，string类型


            }

            string errMsg = "";
            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }
            object domPosition = null;
            ADODB.Connection cnnFrom = null;
            string VouchId = "";
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            bool bCheck = true;
            bool bBeforCheckStock = true;
            bool bIsRedVouch = false;
            string sAddedState = "";
            bool bReMote = false;
            string voucherType = "08";
            errMsg = "";
            //bool Insert(string sVouchType, object DomHead, object domBody, object domPosition, ref string errMsg, ref Connection cnnFrom = null, ref string VouchId = null, ref IXMLDOMDocument2 domMsg = null, ref bool bCheck = true, ref bool bBeforCheckStock = true, bool bIsRedVouch = false, string sAddedState = "", bool bReMote = false);
            object[] args = new object[] { voucherType, domHead, domBody, domPosition, errMsg, cnnFrom, VouchId, domMsg, bCheck, bBeforCheckStock, bIsRedVouch, sAddedState, bReMote };
            string[] paras = { "sVouchType", "DomHead", "domBody", "domPosition", "errMsg", "cnnFrom", "VouchId", "domMsg", "bCheck", "bBeforCheckStock", "bIsRedVouch", "sAddedState", "bReMote" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            //pMod[5] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Insert", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[4].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }

            return "";
        }
        //其他入库单审核
        public string ToYYQTRK_Audit(ADODB.Connection oCon, string id, string utfs1, string strYongYouDBName, string sAccID, string sYear, string sUserID, string sPassword, string sDate, string sServer)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "AS";
            //string sAccID = strAccID;
            //string sYear = strYear;
            //string sUserID = strUserID;
            //string sPassword = strPassword;
            //string sDate = strDate;
            //string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";

            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            //ADODB.Connection oCon = new ADODB.Connection();
            //oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            //oCon.ConnectionString = strConn;
            //oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            string VouchId = id;
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "08";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = utfs1;
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Verify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
            return "";
        }


        //其他入库单弃审
        public string ToYYQTRK_UnAudit(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "08";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Unverify", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }
        //其他入库单删除
        public string ToYYQTRK_Delete(string strYongYouDBName, string strAccID, string strYear, string strUserID, string strPassword, string strDate, string strServer, DataSet dsData)
        {
            //第一步：构造u8login对象并登陆(引用U8API类库中的Interop.U8Login.dll)
            //如果当前环境中有login对象则可以省去第一步
            U8Login.clsLogin u8Login = new U8Login.clsLogin();
            string sSubId = "ST";
            string sAccID = strAccID;
            string sYear = strYear;
            string sUserID = strUserID;
            string sPassword = strPassword;
            string sDate = strDate;
            string sServer = strServer;
            string sSerial = "";
            if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
            {
                string strRet = "登陆失败，原因：" + u8Login.ShareString;
                Marshal.FinalReleaseComObject(u8Login);
                return strRet;
            }
            string errMsg = "";
            string strConn = u8Login.UFDataConnstringForNet;
            strConn = "Provider=SQLOLEDB;" + strConn;
            //string ufdbname = this.oLoginType.InvokeMember("UfDbName", BindingFlags.GetProperty, null, objLogin, null).ToString();
            ADODB.Connection oCon = new ADODB.Connection();
            oCon.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            oCon.ConnectionString = strConn;
            oCon.Open(strConn, "", "", -1);

            Type oType = Type.GetTypeFromProgID("USERPCO.VoucherCO");
            object objPCO = System.Activator.CreateInstance(oType);
            object[] par = new object[] { u8Login, errMsg };
            bool bSuccess = (bool)oType.InvokeMember("IniLogin", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, par);
            if (!bSuccess)
            {
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return errMsg;
            }

            //API参数赋值s
            string VouchId = dsData.Tables[0].DefaultView[0]["ID"].ToString();
            MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
            string voucherType = "08";
            errMsg = "";
            bool bList = false;
            bool bCheck = true;
            bool bBeforCheckStock = true;
            object TimeStamp = dsData.Tables[0].DefaultView[0]["ufts"];
            object[] args = new object[] { voucherType, VouchId, errMsg, TimeStamp, domMsg, bCheck, bList, bBeforCheckStock };
            string[] paras = { "sVouchType", "VouchId", "errMsg", "TimeStamp", "domMsg", "bCheck", "bList", "bBeforCheckStock" };
            ParameterModifier pMod = new ParameterModifier(13);
            pMod[4] = true;
            pMod[6] = true;
            pMod[7] = true;
            pMod[8] = true;
            pMod[9] = true;
            ParameterModifier[] mods = { pMod };
            oCon.BeginTrans();
            bool res = (bool)oType.InvokeMember("Delete", System.Reflection.BindingFlags.InvokeMethod, null, objPCO, args, mods, null, paras);
            if (res)
            {
                oCon.CommitTrans();
                u8Login.ShutDown();
                return "";
            }
            else
            {
                oCon.RollbackTrans();
                u8Login.ShutDown();
                errMsg = args[2].ToString();
                if (errMsg == null)
                    errMsg = "错误：但是没有出错信息";
                return "失败:" + errMsg;
            }
        }

        #endregion
    }
}
